<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .ellipse-container {
      position: relative;
      width: 300px;
      height: 300px;
      border-radius: 50%;
      border: 1px dashed #ccc;
      margin: 50px auto;
    }

    .nav-items {
      position: absolute;
      top: 0%;
      left: 0%;
      width: 100%;
      height: 100%;
      list-style: none;
      padding: 0;
      margin: 0;
      transition: 2s;
      transform-origin: center;
    }

    .nav-item {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 60px;
      height: 30px;
      text-align: center;
      line-height: 30px;
      background-color: #f0f0f0;
      border-radius: 15px;
      transition: 2s;
      /* transform-origin: 0 100px;  */
    }
  </style>
</head>

<body>
  <div class="ellipse-container">
    <ul class="nav-items">
      <li class="nav-item"><span><a href="#">Item 1</a></span></li>
      <li class="nav-item"><span><a href="#">Item 2</a></span></li>
      <li class="nav-item"><span><a href="#">Item 3</a></span></li>
      <li class="nav-item"><span><a href="#">Item 4</a></span></li>
      <li class="nav-item"><span><a href="#">Item 5</a></span></li>
      <li class="nav-item"><span><a href="#">Item 5</a></span></li>

    </ul>
  </div>
  <script>
    function degreesToRadians(degrees) {
      return degrees * (Math.PI / 180);
    }

    let navItems = document.querySelectorAll(".nav-item");
    let navLength = navItems.length;
    let r = 160;
    let step = 360 / navLength;
    for (let i = 0; i < navLength; i++) {
      let deg = step * i;
      let x = r * Math.sin(degreesToRadians(deg));
      let y = -r * Math.cos(degreesToRadians(deg));
      navItems[i].style.transform = `translate(${x}px,${y}px)`
    }

    let currentNav = 2;
    navItems.forEach((nav, index) => {
      nav.addEventListener('click', function (e) {

        // 顺时针旋转
        let chazhi = currentNav - index;
        let cdeg = chazhi * step; // 得到旋转的角度
        document.querySelector(".nav-items").style.transform = `rotate(${cdeg}deg)`;
        for (let i = 0; i < navLength; i++) {
          let deg = step * i;
          let x = r * Math.sin(degreesToRadians(deg));
          let y = -r * Math.cos(degreesToRadians(deg));
          navItems[i].style.transform = `translate(${x}px,${y}px) rotate(${-cdeg}deg)`;
        }

      })
    })
  </script>
</body>

</html>